
import ucigame.*;

import java.awt.AWTException;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;

public class Main extends Ucigame
{

	//constants and other
	//global variable
	///////////

	int windowW = 1279;
	int windowH = 300;

	int gravity = 4;
	int maxAir = 10;

	int speed = 6;

	int frameCounter = 0;
	int frameMod = 2400;

	boolean isGameplay = false;
	boolean isMarathon = true; 

	int currentLevel = 0;
	public static final int MAX_LEVELS = 2;
	
	boolean leftPressed = false;
	boolean rightPressed = false;

	boolean fireOK = false;

	int currentPowerup = 0;

	int currentLives = 3;
	int maxLives = 3;
	int currentHealth = 4;
	int maxHealth = 4;
	boolean invincible = false;
	int currentInvincibleFrame = 0;
	int maxInvincibleFrames = 60;

	int currentMonsterFlicker = 0;
	int maxMonsterFlicker = 20;

	boolean paused = false;

	Sprite bossLeftWall;
	Sprite bossRightWall;

	//these get initialized in setup
	//(also, these are variables that
	//need to be re-initialized to a
	//specific starting state)
	///////////////////////////////

	Sprite player;
	int playerHealth;
	int airTime;
	boolean isRunning;
	boolean isFacingLeft;
	boolean isFacingRight;
	boolean isFiring;

	ArrayList<Sprite> screens;
	int index;

	//floors are any non-enemy, background sprites that give jumps back
	ArrayList<Sprite> floors;
	int floorDrawLimit;

	ArrayList<Bullet> bullets;

	ArrayList<Monster> monsters;
	int monsterDrawLimit;

	ArrayList<Powerup> powerups;
	int powerupDrawLimit;

	ArrayList<Sprite> healthBar;
	ArrayList<Sprite> liveCounter;

	//Variables related to menus
	static final int NUM_MAIN_MENU_BUTTONS = 4,
			MAIN_MENU_BTN_HEIGHT = 55,
			MAIN_MENU_HEIGHT = 640,
			MAIN_MENU_WIDTH = 480,
			NUM_GAME_OVER_BUTTONS = 2;
	
	//Main Menu Sprites
	Sprite mainMenu,startbtn,tutorialBtn,levelbtn,quitbtn;
	//Pause Menu Sprites
	Sprite pauseQuit, pauseResume, pausedScreen, restartBtn;
	//Game Over Sprites
	Sprite gameOver, gameOverQuit;
	//Title Screen
	Sprite titleScreen,levelComplete, level1Complete, level2Complete, lvl1to2bg, lvl2to3bg;
	//Level Select
	Sprite levelSelectBG, lvl1, lvl2,lvl3, lvlback;
	//Tutorial
	Sprite tutorialScreen,tutorialBack;
	
	Image smallQuit, restartImg, backbtn;
	
	Font redFive;
	
	//Sound
	Sound level1Music;
	
	
	
	//set up things
	public void setup()
	{
//		println("start Setup");

		
		//Sound
		level1Music = getSound("music/level1_bg.mp3");

		window.size(windowW, windowH);
		window.title("Extreme Army Knights");
		
		framerate(30);
		
		player = makeSprite(34, 35);
		Image player_image = getImage("images/player.png", 0, 255, 255);
		player.addFrames(player_image,
				5, 3,
				61, 3,
				109, 3,
				153, 3,
				198, 3,
				256, 3,
				318, 3,
				375, 3,
				431, 3,
				493, 3,
				556, 3,
				619, 3); //12 frames added for standing/running
		player.addFrames(player_image,
				9, 196,
				5, 265,
				69, 265,
				130, 265,
				188, 265,
				252, 265,
				313, 265,
				375, 265,
				445, 265,
				512, 265,
				579, 265); //11 frames added for firing standing/running
		player.framerate(20);
		player.defineSequence("Standing", 0);
		player.defineSequence("Running", 1,2,3,4,5,
				6,7,8,9,10,11);
		player.defineSequence("StandFiring", 12);
		player.defineSequence("RunFiring", 13,14,15,
				16,17,18,19,20,21,22);

		airTime = 0;
		isRunning = false;
		isFacingLeft = false;
		isFacingRight = true;
		isFiring = false;

		screens = new ArrayList<Sprite>();
		index = 0;

		floors = new ArrayList<Sprite>();
		floorDrawLimit = 0;

		bullets = new ArrayList<Bullet>();

		monsters = new ArrayList<Monster>();
		monsterDrawLimit = 0;

		powerups = new ArrayList<Powerup>();
		powerupDrawLimit = 0;
		
		currentPowerup = 0;
	
//		try {
//			redFive = Font.createFont(Font.TRUETYPE_FONT, new File("lib/REDFIVE.TTf"));
//		} catch (FontFormatException e) {
//			e.printStackTrace();
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
		
		/*bossLeftWall = makeSprite(getImage("images/boss_wall.png", 0, 255, 255));
		bossLeftWall.position(-5, 0);

		bossRightWall  = makeSprite(getImage("images/boss_wall.png", 0, 255, 255));
		bossRightWall.position(canvas.width(), 0);*/

		liveCounter = new ArrayList<Sprite>();
		for(int lc = 0; lc < maxLives; lc++)
		{
			Sprite temp = makeSprite(16, 17);
			temp.addFrame(getImage("images/lives_health.png", 0, 255, 255),
					2, 2);
			temp.position(10 + lc*20, 5);
			liveCounter.add(temp);
		}

		healthBar = new ArrayList<Sprite>();
		for(int h = 0; h < maxHealth; h++)
		{
			Sprite temp = makeSprite(17, 15);
			temp.addFrame(getImage("images/lives_health.png", 0, 255, 255),
					28, 4);
			temp.position(10 + h*20, 25);
			healthBar.add(temp);
		}


		titleScreen = makeSprite(getImage("images/menus/titleScreen.png"));
		

		
		smallQuit = getImage("images/menus/smallQuit.png");
		restartImg = getImage("images/menus/RestartBtn.png");

		paused = false;
//		println("paused in set up =" +paused);
//		println("setup before !isGameplay");
//		println(currentLives);
		
		if (!isGameplay){
			startScene("TitleScreen");
		}
		else{

			if (currentLives<=0){
				gameOverSetup();
			}
			else{
				switch(currentLevel)
				{
					case 0:
						level1Setup();
						break;
					case 1:
						level2Setup();
						break;
					case 2:
						level3Setup();
						break;
				}
			}
		}
	}
	
	

	/////////
	//Level 1
	/////////

	public void level1Setup()
	{
		//change and set the starting point for the player
//		println("Level1Setup start \n" + paused);
		player.position(0, 200);

		//screens
		/////////

		Sprite screen1 = makeSprite(getImage("images/level1/screen1/Level1_Screen1.png", 0, 255, 255));
		screen1.position(0, 0);

		Sprite screen2 = makeSprite(getImage("images/level1/screen2/Level1_Screen2.png", 0, 255, 255));
		screen2.position(0, 0);

		Sprite screen3 = makeSprite(getImage("images/level1/screen3/Level1_Screen3.png", 0, 255, 255));
		screen3.position(0, 0);

		Sprite screen4 = makeSprite(getImage("images/level1/screen4/Level1_Screen4.png", 0, 255, 255));
		screen4.position(0, 0);

		Sprite screen5 = makeSprite(getImage("images/level1/screen5/Level1_Screen5.png", 0, 255, 255));
		screen5.position(0, 0);

		Sprite screen6 = makeSprite(getImage("images/level1/screen6/Level1_Screen6.png", 0, 255, 255));
		screen6.position(0, 0);

		Sprite screen7 = makeSprite(getImage("images/level1/screen7/Level1_Screen7.png", 0, 255, 255));
		screen7.position(0, 0);

		Sprite screen8 = makeSprite(getImage("images/level1/screen8/Level1_Screen8.png", 0, 255, 255));
		screen8.position(0, 0);

		Sprite screen9 = makeSprite(getImage("images/level1/boss/Level1_Boss.png", 0, 255, 255));
		screen9.position(0, 0);

		screens.add(screen1);
		screens.add(screen2);
		screens.add(screen3);
		screens.add(screen4);
		screens.add(screen5);
		screens.add(screen6);
		screens.add(screen7);
		screens.add(screen8);
		screens.add(screen9);

		//floors
		////////

		//Screen 1 Floors
		//Sprite floor1_01 = makeSprite(getImage("images/floor1_01.png", 0, 255, 255));
		//floor1_01.position(0, canvas.height() - floor1_01.height());

		//JD
		int position = 0;
		Sprite floor1_01 =  makeSprite(getImage("images/level1/screen1/floor1_1.png", 0, 255, 255));
		floor1_01.position(position, canvas.height() - floor1_01.height());
		position+=floor1_01.width();

		Sprite floor1_02 = makeSprite(getImage("images/level1/screen1/floor1_2.png", 0, 255, 255));
		floor1_02.position(position, canvas.height() - floor1_02.height());
		position+=floor1_02.width();

		Sprite floor1_03 = makeSprite(getImage("images/level1/screen1/floor1_3.png", 0, 255, 255));
		floor1_03.position(position, canvas.height() - floor1_03.height());
		position+=floor1_03.width();

		Sprite floor1_04 = makeSprite(getImage("images/level1/screen1/floor1_4.png", 0, 255, 255));
		floor1_04.position(position, canvas.height() - floor1_04.height());
		position+=floor1_04.width();

		Sprite floor1_05 = makeSprite(getImage("images/level1/screen1/floor1_5.png", 0, 255, 255));
		floor1_05.position(position, canvas.height() - floor1_05.height());
		position+=floor1_05.width();

		Sprite floor1_06 = makeSprite(getImage("images/level1/screen1/floor1_6.png", 0, 255, 255));
		floor1_06.position(1098, 167);
		position+=floor1_06.width();

		Sprite floor1_07 = makeSprite(getImage("images/level1/screen1/floor1_7.png", 0, 255, 255));
		floor1_07.position(canvas.width() - floor1_07.width(), canvas.height() - floor1_07.height());

		floors.add(floor1_01);
		floors.add(floor1_02);
		floors.add(floor1_03);
		floors.add(floor1_04);
		floors.add(floor1_05);
		floors.add(floor1_06);
		floors.add(floor1_07);

		//Screen 2 Floors
		position = 0;
		Sprite floor2_01 = makeSprite(getImage("images/level1/screen2/floor2_1.png", 0, 255, 255));
		floor2_01.position(0, canvas.height() - floor2_01.height() + 10);

		Sprite floor2_02 = makeSprite(getImage("images/level1/screen2/floor2_2.png", 0, 255, 255));
		floor2_02.position(118, canvas.height() - floor2_02.height());
		position += floor2_02.width()+118;//special case pit in between

		Sprite floor2_03 = makeSprite(getImage("images/level1/screen2/floor2_3.png", 0, 255, 255));
		floor2_03.position(position, canvas.height() - floor2_03.height());
		position += floor2_03.width();

		Sprite floor2_04 = makeSprite(getImage("images/level1/screen2/floor2_4.png", 0, 255, 255));
		floor2_04.position(position, canvas.height() - floor2_04.height());
		position += floor2_04.width();

		Sprite floor2_05 = makeSprite(getImage("images/level1/screen2/floor2_5.png", 0, 255, 255));
		floor2_05.position(position, canvas.height() - floor2_05.height());
		position += floor2_05.width();

		Sprite floor2_06 = makeSprite(getImage("images/level1/screen2/floor2_6.png", 0, 255, 255));
		floor2_06.position(position, canvas.height() - floor2_06.height());
		position += floor2_06.width();

		Sprite floor2_07 = makeSprite(getImage("images/level1/screen2/floor2_7.png", 0, 255, 255));
		floor2_07.position(position, canvas.height() - floor2_07.height());
		position += floor2_07.width();

		Sprite floor2_08 = makeSprite(getImage("images/level1/screen2/floor2_8.png", 0, 255, 255));
		floor2_08.position(position, canvas.height() - floor2_08.height());
		position += floor2_08.width();

		Sprite floor2_09 = makeSprite(getImage("images/level1/screen2/floor2_9.png", 0, 255, 255));
		floor2_09.position(907, canvas.height() - floor2_09.height());
		position = floor2_09.width() + 907;

		Sprite floor2_10 = makeSprite(getImage("images/level1/screen2/floor2_10.png", 0, 255, 255));
		floor2_10.position(position, canvas.height() - floor2_10.height());
		position += floor2_10.width();

		Sprite floor2_11 = makeSprite(getImage("images/level1/screen2/floor2_11.png", 0, 255, 255));
		floor2_11.position(position, canvas.height() - floor2_11.height());
		position += floor2_11.width();

		Sprite floor2_12 = makeSprite(getImage("images/level1/screen2/floor2_12.png", 0, 255, 255));
		floor2_12.position(canvas.width() - floor2_12.width(), canvas.height() - floor2_12.height());
		position += floor2_12.width() + 236;

		//Sprite platform2_01 = makeSprite(getImage("images/platform1_02.png", 0, 255, 255));
		//platform2_01.position(200, 310);

		floors.add(floor2_01);
		floors.add(floor2_02);
		floors.add(floor2_03);
		floors.add(floor2_04);
		floors.add(floor2_05);
		floors.add(floor2_06);
		floors.add(floor2_07);
		floors.add(floor2_08);
		floors.add(floor2_09);
		floors.add(floor2_10);
		floors.add(floor2_11);
		floors.add(floor2_12);

		//floors.add(platform2_01);

		//Screen 3 Floors
		position = 0;
		Sprite floor3_01 = makeSprite(getImage("images/level1/screen3/floor3_1.png", 0, 255, 255));
		floor3_01.position(0, canvas.height() - floor3_01.height() + 10);
		position += floor3_01.width(); 
//		System.out.println("position: " + position);


		Sprite floor3_02 = makeSprite(getImage("images/level1/screen3/floor3_2.png", 0, 255, 255));
		floor3_02.position(position, canvas.height() - floor3_02.height());
		position += floor3_02.width();

//		System.out.println("position: " + position);
		Sprite floor3_03 = makeSprite(getImage("images/level1/screen3/floor3_3.png", 0, 255, 255));
		floor3_03.position(position, canvas.height() - floor3_03.height());
		position += floor3_03.width();

//		System.out.println("position: " + position);
		Sprite floor3_04 = makeSprite(getImage("images/level1/screen3/floor3_4.png", 0, 255, 255));
		floor3_04.position(position, canvas.height() - floor3_04.height());
		position += floor3_04.width();

//		System.out.println("position: " + position);
		Sprite floor3_05 = makeSprite(getImage("images/level1/screen3/floor3_5.png", 0, 255, 255));
		floor3_05.position(331, canvas.height() - floor3_05.height());
		position = floor3_05.width()+ 331;

		Sprite floor3_06 = makeSprite(getImage("images/level1/screen3/floor3_6.png", 0, 255, 255));
		floor3_06.position(position, canvas.height() - floor3_06.height());
		position += floor3_06.width();

		Sprite floor3_07 = makeSprite(getImage("images/level1/screen3/floor3_7.png", 0, 255, 255));
		floor3_07.position(position, canvas.height() - floor3_07.height());
		position += floor3_07.width();

		Sprite floor3_08 = makeSprite(getImage("images/level1/screen3/floor3_8.png", 0, 255, 255));
		floor3_08.position(569, canvas.height() - floor3_08.height());
		position = floor3_08.width() + 569;

		Sprite floor3_09 = makeSprite(getImage("images/level1/screen3/floor3_9.png", 0, 255, 255));
		floor3_09.position(position, canvas.height() - floor3_09.height());
		position += floor3_09.width();

		Sprite floor3_10 = makeSprite(getImage("images/level1/screen3/floor3_10.png", 0, 255, 255));
		floor3_10.position(position, canvas.height() - floor3_10.height());
		position += floor3_10.width();

		Sprite floor3_12 = makeSprite(getImage("images/level1/screen3/floor3_12.png", 0, 255, 255));
		floor3_12.position(1142, canvas.height() - floor3_12.height());
		position = floor3_12.width() + 1142;


		Sprite floor3_11 = makeSprite(getImage("images/level1/screen3/floor3_11.png", 0, 255, 255));
		floor3_11.position(position, canvas.height() - floor3_11.height());
		position += floor3_11.width();

		floors.add(floor3_01);
		floors.add(floor3_02);
		floors.add(floor3_03);
		floors.add(floor3_04);
		floors.add(floor3_05);
		floors.add(floor3_06);
		floors.add(floor3_07);
		floors.add(floor3_08);
		floors.add(floor3_09);
		floors.add(floor3_10);
		floors.add(floor3_12);
		floors.add(floor3_11);


		//Screen 4 Floors
		position = 0;
		Sprite floor4_01 = makeSprite(getImage("images/level1/screen4/floor4_1.png", 0, 255, 255));
		floor4_01.position(0, canvas.height() - floor4_01.height() + 10);

		Sprite floor4_02 = makeSprite(getImage("images/level1/screen4/floor4_2.png", 0, 255, 255));
		floor4_02.position(341, canvas.height() - floor4_02.height());
		position += floor4_02.width() + 341;

		Sprite floor4_03 = makeSprite(getImage("images/level1/screen4/floor4_3.png", 0, 255, 255));
		floor4_03.position(position, canvas.height() - floor4_03.height());
		position += floor4_03.width();

		Sprite floor4_04 = makeSprite(getImage("images/level1/screen4/floor4_4.png", 0, 255, 255));
		floor4_04.position(position, canvas.height() - floor4_04.height());
		position += floor4_04.width();

		floors.add(floor4_01);
		floors.add(floor4_02);
		floors.add(floor4_03);
		floors.add(floor4_04);

		//Screen 5 Floors
		position = 0;
		Sprite floor5_01 = makeSprite(getImage("images/level1/screen5/floor5_1.png", 0, 255, 255));
		floor5_01.position(0, canvas.height() - floor5_01.height() + 10);

		Sprite floor5_02 = makeSprite(getImage("images/level1/screen5/floor5_2.png", 0, 255, 255));
		floor5_02.position(328, 167);

		Sprite floor5_03 = makeSprite(getImage("images/level1/screen5/floor5_3.png", 0, 255, 255));
		floor5_03.position(443, canvas.height() - floor5_03.height());

		Sprite floor5_04 = makeSprite(getImage("images/level1/screen5/floor5_4.png", 0, 255, 255));
		floor5_04.position(484, 119);

		Sprite floor5_05 = makeSprite(getImage("images/level1/screen5/floor5_5.png", 0, 255, 255));
		floor5_05.position(515, 66);
		position += floor5_05.width() + 515;

		Sprite floor5_06 = makeSprite(getImage("images/level1/screen5/floor5_6.png", 0, 255, 255));
		floor5_06.position(position, canvas.height() - floor5_06.height());
		position += floor5_06.width();

		Sprite floor5_07 = makeSprite(getImage("images/level1/screen5/floor5_7.png", 0, 255, 255));
		floor5_07.position(position, canvas.height() - floor5_07.height());
		position += floor5_07.width();

		Sprite floor5_08 = makeSprite(getImage("images/level1/screen5/floor5_8.png", 0, 255, 255));
		floor5_08.position(position, canvas.height() - floor5_08.height());

		floors.add(floor5_01);
		floors.add(floor5_02);
		floors.add(floor5_03);
		floors.add(floor5_04);
		floors.add(floor5_05);
		floors.add(floor5_06);
		floors.add(floor5_07);
		floors.add(floor5_08);

		//Screen 6
		position = 0;
		Sprite floor6_01 = makeSprite(getImage("images/level1/screen6/floor6_1.png", 0, 255, 255));
		floor6_01.position(0, canvas.height() - floor6_01.height() + 10);
		position += floor6_01.width();

		Sprite floor6_02 = makeSprite(getImage("images/level1/screen6/floor6_2.png", 0, 255, 255));
		floor6_02.position(position, canvas.height() - floor6_02.height());
		position += floor6_02.width();

		Sprite floor6_03 = makeSprite(getImage("images/level1/screen6/floor6_3.png", 0, 255, 255));
		floor6_03.position(position, canvas.height() - floor6_03.height());
		position += floor6_03.width();

		Sprite floor6_04 = makeSprite(getImage("images/level1/screen6/floor6_4.png", 0, 255, 255));
		floor6_04.position(position, canvas.height() - floor6_04.height());
		position += floor6_04.width();

		Sprite floor6_05 = makeSprite(getImage("images/level1/screen6/floor6_5.png", 0, 255, 255));
		floor6_05.position(position, canvas.height() - floor6_05.height());
		position += floor6_05.width();

		Sprite floor6_06 = makeSprite(getImage("images/level1/screen6/floor6_6.png", 0, 255, 255));
		floor6_06.position(position, canvas.height() - floor6_06.height());
		position += floor6_06.width();

		Sprite floor6_07 = makeSprite(getImage("images/level1/screen6/floor6_7.png", 0, 255, 255));
		floor6_07.position(position, canvas.height() - floor6_07.height());
		position += floor6_07.width();

		floors.add(floor6_01);
		floors.add(floor6_02);
		floors.add(floor6_03);
		floors.add(floor6_04);
		floors.add(floor6_05);
		floors.add(floor6_06);
		floors.add(floor6_07);

		//Screen 7
		position = 0;
		Sprite floor7_01 = makeSprite(getImage("images/level1/screen7/floor7_1.png", 0, 255, 255));
		floor7_01.position(position, canvas.height() - floor7_01.height()+ 5 + 10);
		position += floor7_01.width();

		Sprite floor7_02 = makeSprite(getImage("images/level1/screen7/floor7_2.png", 0, 255, 255));
		floor7_02.position(position, canvas.height() - floor7_02.height());
		position += floor7_02.width();

		Sprite floor7_03 = makeSprite(getImage("images/level1/screen7/floor7_3.png", 0, 255, 255));
		floor7_03.position(position, canvas.height() - floor7_03.height());
		position += floor7_03.width();

		Sprite floor7_04 = makeSprite(getImage("images/level1/screen7/floor7_4.png", 0, 255, 255));
		floor7_04.position(position, canvas.height() - floor7_04.height());
		position += floor7_01.width();

		floors.add(floor7_01);
		floors.add(floor7_02);
		floors.add(floor7_03);
		floors.add(floor7_04);

		//Screen 8
		position = 0;
		Sprite floor8_01 = makeSprite(getImage("images/level1/screen8/floor8_1.png", 0, 255, 255));
		floor8_01.position(position, canvas.height() - floor8_01.height() + 10);
		position += floor8_01.width();

		Sprite floor8_02 = makeSprite(getImage("images/level1/screen8/floor8_2.png", 0, 255, 255));
		floor8_02.position(position, canvas.height() - floor8_02.height());
		position += floor8_02.width();

		floors.add(floor8_01);
		floors.add(floor8_02);

		//Screen 9
		position = 0;
		Sprite floor9_01 = makeSprite(getImage("images/level1/boss/floor9_1.png", 0, 255, 255));
		floor9_01.position(position, canvas.height() - floor9_01.height() + 10);
		position += floor9_01.width();

		floors.add(floor9_01);


		//Boss Walls for boss screen
		bossLeftWall = makeSprite(getImage("images/boss_wall.png", 0, 255, 255));
		bossLeftWall.position(-5, 0);

		bossRightWall  = makeSprite(getImage("images/boss_wall.png", 0, 255, 255));

		bossRightWall.position(canvas.width() - bossRightWall.width(), 0);
		//bossLeftWall.position(0, 0);

		floors.add(bossRightWall);
		floors.add(bossLeftWall);

		//Monsters
		/////////

		//1
		Monster monster1_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
				15, 17);
		monster1_01.position(700, 240);

		monsters.add(monster1_01);

		//2
		Monster monster2_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
				15, 17);
		monster2_01.position(350, 260);

		monsters.add(monster2_01);

		//3
		Monster monster3_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
				15, 17);
		monster3_01.position(900, 220);

		monsters.add(monster3_01);

		//6
		Monster monster6_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
				15, 17);
		monster6_01.position(200, 240);

		Monster monster6_02 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
				15, 17);
		monster6_02.position(670, 200);

		Monster monster6_03 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
				15, 17);
		monster6_03.position(1080, 200);

		monsters.add(monster6_01);
		monsters.add(monster6_02);
		monsters.add(monster6_03);

		//7
		Monster monster7_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
				15, 17);
		monster7_01.position(340, 200);

		Monster monster7_02 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
				15, 17);
		monster7_02.position(816, 190);

		Monster monster7_03 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
				15, 17);
		monster7_03.position(1160, 170);

		monsters.add(monster7_01);
		monsters.add(monster7_02);
		monsters.add(monster7_03);

		//8
		//Monster monster8_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
		//	15, 17);
		//monster8_01.position(1200, 215);

		//monsters.add(monster8_01);

		//Boss Level 1 (Monster Here)
		Monster monster9_01 = new Monster(1000, frameCounter, getImage("images/bosses.png", 0, 255, 255),
				28, 50);
		monster9_01.position(1130, 200);
		monsters.add(monster9_01);

		//powerups
		//////////

		//1
		Powerup power1_01 = new Powerup(1, getImage("images/powerups.png", 0, 255, 255), 20, 20);
		power1_01.position(320, canvas.height() - 35);

		powerups.add(power1_01);

		startScene("Level1");
//		println("Level1Setup end \n" + paused);
	}

	public void drawLevel1()
	{
		if(!paused)
		{
			canvas.clear();

			drawScreens();

			//draw the floors for the specified screen
			switch(index)
			{
			case 0:
				floorDrawLimit = 7;//7 floor objects in screen1
				powerupDrawLimit = 1;
				monsterDrawLimit = 1;
				break;
			case 1:
				floorDrawLimit = 12;//12 floor objects in screen2
				powerupDrawLimit = 0;
				monsterDrawLimit = 1;
				break;
			case 2:
				floorDrawLimit = 12;//11 floor objects in screen3
				powerupDrawLimit = 0;
				monsterDrawLimit = 1;
				break;
			case 3:
				floorDrawLimit = 4;//4 floor objects in screen 4
				powerupDrawLimit = 0;
				monsterDrawLimit = 0;
				break;
			case 4:
				floorDrawLimit = 8;//8 floor objects in screen 5
				powerupDrawLimit = 0;
				monsterDrawLimit = 0;
				break;
			case 5:
				floorDrawLimit = 7;//7 floor objects in screen 6
				powerupDrawLimit = 0;
				monsterDrawLimit = 3;
				break;
			case 6:
				floorDrawLimit = 4;//4 floor objects in screen 7
				powerupDrawLimit = 0;
				monsterDrawLimit = 3;
				break;
			case 7:
				floorDrawLimit = 2;//7 floor objects in screen 8
				powerupDrawLimit = 0;
				monsterDrawLimit = 0;
				break;
			case 8:
				//checks if all enemies are dead in boss room
				boolean roomClear = true;
				for(int t = 0; t < monsters.size(); t++)
				{
					if(!monsters.get(t).isDead())
					{
						roomClear = false;
					}
				}

				if(roomClear)
				{
					floorDrawLimit = 1;//Boss floor object
				}
				else
				{
					floorDrawLimit = 3;//includes side walls
				}
				powerupDrawLimit = 0;
				monsterDrawLimit = 1;
				break;
			default:
				floorDrawLimit = 0;
				powerupDrawLimit = 0;
				monsterDrawLimit = 0;
			}

			drawFloors();

			drawPlayer();

			drawHealthLives();

			drawPowerups();

			drawMonsters();

			drawBullets();

			playerMovement();

			bulletMovement();

			monsterMovement();

			playerFloorCollision();

			monsterFloorCollision();

			bulletCollision();

			playerMonsterCollision();

			powerupCollision();

			screenChange();

			incrementFrames();
		}
		else
		{
			canvas.clear();
			pauseMenuSetup();

		}
	}

	public void onKeyPressLevel1()
	{
		keyPressLevels();
	}


	/////////
	//Level 2
	/////////

	public void level2Setup()
	{
		//change and set the starting point for the player
		player.position(0, 200);

		//screens
		/////////

		Sprite screen1 = makeSprite(getImage("images/level2/screen1/Level2_Screen1.png", 0, 255, 255));
		screen1.position(0, 0);
		/*
				Sprite screen2 = makeSprite(getImage("images/level2/screen2/Level2_Screen2.png", 0, 255, 255));
				screen2.position(0, 0);

				Sprite screen3 = makeSprite(getImage("images/level1/screen3/Level1_Screen3.png", 0, 255, 255));
				screen3.position(0, 0);

				Sprite screen4 = makeSprite(getImage("images/level1/screen4/Level1_Screen4.png", 0, 255, 255));
				screen4.position(0, 0);

				Sprite screen5 = makeSprite(getImage("images/level1/screen5/Level1_Screen5.png", 0, 255, 255));
				screen5.position(0, 0);

				Sprite screen6 = makeSprite(getImage("images/level1/screen6/Level1_Screen6.png", 0, 255, 255));
				screen6.position(0, 0);

				Sprite screen7 = makeSprite(getImage("images/level1/screen7/Level1_Screen7.png", 0, 255, 255));
				screen7.position(0, 0);

				Sprite screen8 = makeSprite(getImage("images/level1/screen8/Level1_Screen8.png", 0, 255, 255));
				screen8.position(0, 0);

				Sprite screen9 = makeSprite(getImage("images/level1/boss/Level1_Boss.png", 0, 255, 255));
				screen9.position(0, 0);
		 */

		screens.add(screen1);
		/*
				screens.add(screen2);
				screens.add(screen3);
				screens.add(screen4);
				screens.add(screen5);
				screens.add(screen6);
				screens.add(screen7);
				screens.add(screen8);
				screens.add(screen9);
		 */

		//floors
		////////

		//Screen 1 Floors
		//Sprite floor1_01 = makeSprite(getImage("images/floor1_01.png", 0, 255, 255));
		//floor1_01.position(0, canvas.height() - floor1_01.height());

		//JD
		int position = 0;
		Sprite floor1_01 =  makeSprite(getImage("images/level2/screen1/floor1_1.png", 0, 255, 255));
		floor1_01.position(position, canvas.height() - floor1_01.height());
		position+=floor1_01.width();

		Sprite floor1_02 = makeSprite(getImage("images/level2/screen1/floor1_2.png", 0, 255, 255));
		floor1_02.position(position, canvas.height() - floor1_02.height());
		position+=floor1_02.width();

		Sprite floor1_03 = makeSprite(getImage("images/level2/screen1/floor1_3.png", 0, 255, 255));
		floor1_03.position(position, canvas.height() - floor1_03.height());
		position+=floor1_03.width();

		Sprite floor1_04 = makeSprite(getImage("images/level2/screen1/floor1_4.png", 0, 255, 255));
		floor1_04.position(position, canvas.height() - floor1_04.height());
		position+=floor1_04.width();

		floors.add(floor1_01);
		floors.add(floor1_02);
		floors.add(floor1_03);
		floors.add(floor1_04);

		/*
				//Screen 2 Floors
				position = 0;
				Sprite floor2_01 = makeSprite(getImage("images/level2/screen2/floor2_1.png", 0, 255, 255));
				floor2_01.position(0, canvas.height() - floor2_01.height() + 10);
				position += floor2_01.width();

				Sprite floor2_02 = makeSprite(getImage("images/level2/screen2/floor2_2.png", 0, 255, 255));
				floor2_02.position(118, canvas.height() - floor2_02.height() + 10);
				position += floor2_02.width();//special case pit in between

				Sprite floor2_03 = makeSprite(getImage("images/level2/screen2/floor2_3.png", 0, 255, 255));
				floor2_03.position(position, canvas.height() - floor2_03.height() + 10);
				position += floor2_03.width();

				Sprite floor2_04 = makeSprite(getImage("images/level2/screen2/floor2_4.png", 0, 255, 255));
				floor2_04.position(position, canvas.height() - floor2_04.height() + 10);
				position += floor2_04.width();

				Sprite floor2_05 = makeSprite(getImage("images/level2/screen2/floor2_5.png", 0, 255, 255));
				floor2_05.position(position, canvas.height() - floor2_05.height() + 10);
				position += floor2_05.width();

				Sprite floor2_06 = makeSprite(getImage("images/level2/screen2/floor2_6.png", 0, 255, 255));
				floor2_06.position(position, canvas.height() - floor2_06.height() + 10);
				position += floor2_06.width();

				Sprite floor2_07 = makeSprite(getImage("images/level2/screen2/floor2_7.png", 0, 255, 255));
				floor2_07.position(position, canvas.height() - floor2_07.height() + 10);
				position += floor2_07.width();

				Sprite floor2_08 = makeSprite(getImage("images/level2/screen2/floor2_8.png", 0, 255, 255));
				floor2_08.position(position, canvas.height() - floor2_08.height() + 10);
				position += floor2_08.width();

				Sprite floor2_09 = makeSprite(getImage("images/level2/screen2/floor2_9.png", 0, 255, 255));
				floor2_09.position(907, canvas.height() - floor2_09.height() + 10);
				position = floor2_09.width();

				Sprite floor2_10 = makeSprite(getImage("images/level2/screen2/floor2_10.png", 0, 255, 255));
				floor2_10.position(position, canvas.height() - floor2_10.height() + 10);
				position += floor2_10.width();

				Sprite floor2_11 = makeSprite(getImage("images/level2/screen2/floor2_11.png", 0, 255, 255));
				floor2_11.position(position, canvas.height() - floor2_11.height() + 10);
				position += floor2_11.width();

				Sprite floor2_12 = makeSprite(getImage("images/level2/screen2/floor2_12.png", 0, 255, 255));
				floor2_12.position(canvas.width() - floor2_12.width(), canvas.height() - floor2_12.height() + 10);
				position += floor2_12.width();

				Sprite floor2_13 = makeSprite(getImage("images/level2/screen2/floor2_13.png", 0, 255, 255));
				floor2_13.position(canvas.width() - floor2_13.width(), canvas.height() - floor2_13.height() + 10);
				position += floor2_13.width();

				Sprite floor2_14 = makeSprite(getImage("images/level2/screen2/floor2_14.png", 0, 255, 255));
				floor2_14.position(canvas.width() - floor2_14.width(), canvas.height() - floor2_14.height() + 10);
				position += floor2_14.width();

				//Sprite platform2_01 = makeSprite(getImage("images/platform1_02.png", 0, 255, 255));
				//platform2_01.position(200, 310);

				floors.add(floor2_01);
				floors.add(floor2_02);
				floors.add(floor2_03);
				floors.add(floor2_04);
				floors.add(floor2_05);
				floors.add(floor2_06);
				floors.add(floor2_07);
				floors.add(floor2_08);
				floors.add(floor2_09);
				floors.add(floor2_10);
				floors.add(floor2_11);
				floors.add(floor2_12);
				floors.add(floor2_13);
				floors.add(floor2_14);


				//floors.add(platform2_01);

				//Screen 3 Floors
				position = 0;
				Sprite floor3_01 = makeSprite(getImage("images/level1/screen3/floor3_1.png", 0, 255, 255));
				floor3_01.position(0, canvas.height() - floor3_01.height() + 10);
				position += floor3_01.width(); 
				System.out.println("position: " + position);


				Sprite floor3_02 = makeSprite(getImage("images/level1/screen3/floor3_2.png", 0, 255, 255));
				floor3_02.position(position, canvas.height() - floor3_02.height());
				position += floor3_02.width();

				System.out.println("position: " + position);
				Sprite floor3_03 = makeSprite(getImage("images/level1/screen3/floor3_3.png", 0, 255, 255));
				floor3_03.position(position, canvas.height() - floor3_03.height());
				position += floor3_03.width();

				System.out.println("position: " + position);
				Sprite floor3_04 = makeSprite(getImage("images/level1/screen3/floor3_4.png", 0, 255, 255));
				floor3_04.position(position, canvas.height() - floor3_04.height());
				position += floor3_04.width();

				System.out.println("position: " + position);
				Sprite floor3_05 = makeSprite(getImage("images/level1/screen3/floor3_5.png", 0, 255, 255));
				floor3_05.position(331, canvas.height() - floor3_05.height());
				position = floor3_05.width()+ 331;

				Sprite floor3_06 = makeSprite(getImage("images/level1/screen3/floor3_6.png", 0, 255, 255));
				floor3_06.position(position, canvas.height() - floor3_06.height());
				position += floor3_06.width();

				Sprite floor3_07 = makeSprite(getImage("images/level1/screen3/floor3_7.png", 0, 255, 255));
				floor3_07.position(position, canvas.height() - floor3_07.height());
				position += floor3_07.width();

				Sprite floor3_08 = makeSprite(getImage("images/level1/screen3/floor3_8.png", 0, 255, 255));
				floor3_08.position(569, canvas.height() - floor3_08.height());
				position = floor3_08.width() + 569;

				Sprite floor3_09 = makeSprite(getImage("images/level1/screen3/floor3_9.png", 0, 255, 255));
				floor3_09.position(position, canvas.height() - floor3_09.height());
				position += floor3_09.width();

				Sprite floor3_10 = makeSprite(getImage("images/level1/screen3/floor3_10.png", 0, 255, 255));
				floor3_10.position(position, canvas.height() - floor3_10.height());
				position += floor3_10.width();

				Sprite floor3_12 = makeSprite(getImage("images/level1/screen3/floor3_12.png", 0, 255, 255));
				floor3_12.position(1142, canvas.height() - floor3_12.height());
				position = floor3_12.width() + 1142;


				Sprite floor3_11 = makeSprite(getImage("images/level1/screen3/floor3_11.png", 0, 255, 255));
				floor3_11.position(position, canvas.height() - floor3_11.height());
				position += floor3_11.width();

				floors.add(floor3_01);
				floors.add(floor3_02);
				floors.add(floor3_03);
				floors.add(floor3_04);
				floors.add(floor3_05);
				floors.add(floor3_06);
				floors.add(floor3_07);
				floors.add(floor3_08);
				floors.add(floor3_09);
				floors.add(floor3_10);
				floors.add(floor3_12);
				floors.add(floor3_11);


				//Screen 4 Floors
				position = 0;
				Sprite floor4_01 = makeSprite(getImage("images/level1/screen4/floor4_1.png", 0, 255, 255));
				floor4_01.position(0, canvas.height() - floor4_01.height() + 10);

				Sprite floor4_02 = makeSprite(getImage("images/level1/screen4/floor4_2.png", 0, 255, 255));
				floor4_02.position(341, canvas.height() - floor4_02.height());
				position += floor4_02.width() + 341;

				Sprite floor4_03 = makeSprite(getImage("images/level1/screen4/floor4_3.png", 0, 255, 255));
				floor4_03.position(position, canvas.height() - floor4_03.height());
				position += floor4_03.width();

				Sprite floor4_04 = makeSprite(getImage("images/level1/screen4/floor4_4.png", 0, 255, 255));
				floor4_04.position(position, canvas.height() - floor4_04.height());
				position += floor4_04.width();

				floors.add(floor4_01);
				floors.add(floor4_02);
				floors.add(floor4_03);
				floors.add(floor4_04);

				//Screen 5 Floors
				position = 0;
				Sprite floor5_01 = makeSprite(getImage("images/level1/screen5/floor5_1.png", 0, 255, 255));
				floor5_01.position(0, canvas.height() - floor5_01.height() + 10);

				Sprite floor5_02 = makeSprite(getImage("images/level1/screen5/floor5_2.png", 0, 255, 255));
				floor5_02.position(328, 167);

				Sprite floor5_03 = makeSprite(getImage("images/level1/screen5/floor5_3.png", 0, 255, 255));
				floor5_03.position(443, canvas.height() - floor5_03.height());

				Sprite floor5_04 = makeSprite(getImage("images/level1/screen5/floor5_4.png", 0, 255, 255));
				floor5_04.position(484, 119);

				Sprite floor5_05 = makeSprite(getImage("images/level1/screen5/floor5_5.png", 0, 255, 255));
				floor5_05.position(515, 66);
				position += floor5_05.width() + 515;

				Sprite floor5_06 = makeSprite(getImage("images/level1/screen5/floor5_6.png", 0, 255, 255));
				floor5_06.position(position, canvas.height() - floor5_06.height());
				position += floor5_06.width();

				Sprite floor5_07 = makeSprite(getImage("images/level1/screen5/floor5_7.png", 0, 255, 255));
				floor5_07.position(position, canvas.height() - floor5_07.height());
				position += floor5_07.width();

				Sprite floor5_08 = makeSprite(getImage("images/level1/screen5/floor5_8.png", 0, 255, 255));
				floor5_08.position(position, canvas.height() - floor5_08.height());

				floors.add(floor5_01);
				floors.add(floor5_02);
				floors.add(floor5_03);
				floors.add(floor5_04);
				floors.add(floor5_05);
				floors.add(floor5_06);
				floors.add(floor5_07);
				floors.add(floor5_08);

				//Screen 6
				position = 0;
				Sprite floor6_01 = makeSprite(getImage("images/level1/screen6/floor6_1.png", 0, 255, 255));
				floor6_01.position(0, canvas.height() - floor6_01.height() + 10);
				position += floor6_01.width();

				Sprite floor6_02 = makeSprite(getImage("images/level1/screen6/floor6_2.png", 0, 255, 255));
				floor6_02.position(position, canvas.height() - floor6_02.height());
				position += floor6_02.width();

				Sprite floor6_03 = makeSprite(getImage("images/level1/screen6/floor6_3.png", 0, 255, 255));
				floor6_03.position(position, canvas.height() - floor6_03.height());
				position += floor6_03.width();

				Sprite floor6_04 = makeSprite(getImage("images/level1/screen6/floor6_4.png", 0, 255, 255));
				floor6_04.position(position, canvas.height() - floor6_04.height());
				position += floor6_04.width();

				Sprite floor6_05 = makeSprite(getImage("images/level1/screen6/floor6_5.png", 0, 255, 255));
				floor6_05.position(position, canvas.height() - floor6_05.height());
				position += floor6_05.width();

				Sprite floor6_06 = makeSprite(getImage("images/level1/screen6/floor6_6.png", 0, 255, 255));
				floor6_06.position(position, canvas.height() - floor6_06.height());
				position += floor6_06.width();

				Sprite floor6_07 = makeSprite(getImage("images/level1/screen6/floor6_7.png", 0, 255, 255));
				floor6_07.position(position, canvas.height() - floor6_07.height());
				position += floor6_07.width();

				floors.add(floor6_01);
				floors.add(floor6_02);
				floors.add(floor6_03);
				floors.add(floor6_04);
				floors.add(floor6_05);
				floors.add(floor6_06);
				floors.add(floor6_07);

				//Screen 7
				position = 0;
				Sprite floor7_01 = makeSprite(getImage("images/level1/screen7/floor7_1.png", 0, 255, 255));
				floor7_01.position(position, canvas.height() - floor7_01.height()+ 5 + 10);
				position += floor7_01.width();

				Sprite floor7_02 = makeSprite(getImage("images/level1/screen7/floor7_2.png", 0, 255, 255));
				floor7_02.position(position, canvas.height() - floor7_02.height());
				position += floor7_02.width();

				Sprite floor7_03 = makeSprite(getImage("images/level1/screen7/floor7_3.png", 0, 255, 255));
				floor7_03.position(position, canvas.height() - floor7_03.height());
				position += floor7_03.width();

				Sprite floor7_04 = makeSprite(getImage("images/level1/screen7/floor7_4.png", 0, 255, 255));
				floor7_04.position(position, canvas.height() - floor7_04.height());
				position += floor7_01.width();

				floors.add(floor7_01);
				floors.add(floor7_02);
				floors.add(floor7_03);
				floors.add(floor7_04);

				//Screen 8
				position = 0;
				Sprite floor8_01 = makeSprite(getImage("images/level1/screen8/floor8_1.png", 0, 255, 255));
				floor8_01.position(position, canvas.height() - floor8_01.height() + 10);
				position += floor8_01.width();

				Sprite floor8_02 = makeSprite(getImage("images/level1/screen8/floor8_2.png", 0, 255, 255));
				floor8_02.position(position, canvas.height() - floor8_02.height());
				position += floor8_02.width();

				floors.add(floor8_01);
				floors.add(floor8_02);

				//Screen 9
				position = 0;
				Sprite floor9_01 = makeSprite(getImage("images/level1/boss/floor9_1.png", 0, 255, 255));
				floor9_01.position(position, canvas.height() - floor9_01.height() + 10);
				position += floor9_01.width();

				floors.add(floor9_01);


				//Boss Walls for boss screen
				bossLeftWall = makeSprite(getImage("images/boss_wall.png", 0, 255, 255));
				bossLeftWall.position(-5, 0);

				bossRightWall  = makeSprite(getImage("images/boss_wall.png", 0, 255, 255));

				bossRightWall.position(canvas.width() - bossRightWall.width(), 0);
				//bossLeftWall.position(0, 0);

				floors.add(bossRightWall);
				floors.add(bossLeftWall);

				//Monsters
				/////////

				//1
				Monster monster1_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
						15, 17);
				monster1_01.position(700, 240);

				monsters.add(monster1_01);

				//2
				Monster monster2_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
						15, 17);
				monster2_01.position(350, 260);

				monsters.add(monster2_01);

				//3
				Monster monster3_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
						15, 17);
				monster3_01.position(900, 220);

				monsters.add(monster3_01);

				//6
				Monster monster6_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
						15, 17);
				monster6_01.position(200, 240);

				Monster monster6_02 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
						15, 17);
				monster6_02.position(670, 200);

				Monster monster6_03 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
						15, 17);
				monster6_03.position(1080, 200);

				monsters.add(monster6_01);
				monsters.add(monster6_02);
				monsters.add(monster6_03);

				//7
				Monster monster7_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
						15, 17);
				monster7_01.position(340, 200);

				Monster monster7_02 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
						15, 17);
				monster7_02.position(816, 190);

				Monster monster7_03 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
						15, 17);
				monster7_03.position(1160, 170);

				monsters.add(monster7_01);
				monsters.add(monster7_02);
				monsters.add(monster7_03);

				//8
				//Monster monster8_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
				//	15, 17);
				//monster8_01.position(1200, 215);

				//monsters.add(monster8_01);

				//Boss Level 2 (Monster Here)
				Monster monster9_01 = new Monster(1000, frameCounter, getImage("images/bosses.png", 0, 255, 255),
						28, 50);
				monster9_01.position(1130, 200);
				monsters.add(monster9_01);

				//powerups
				//////////

				//1
				Powerup power2_01 = new Powerup(1, getImage("images/powerups.png", 0, 255, 255), 20, 20);
				power2_01.position(320, canvas.height() - 35);

				powerups.add(power2_01);
		 */

		startScene("Level2");
	}

	public void drawLevel2()
	{
		if(!paused)
		{
			canvas.clear();

			drawScreens();

			//draw the floors for the specified screen
			switch(index)
			{
			case 0:
				floorDrawLimit = 4;//7 floor objects in screen1
				powerupDrawLimit = 1;
				monsterDrawLimit = 1;
				break;
				/*
				case 1:
					floorDrawLimit = 0;//12 floor objects in screen2
					powerupDrawLimit = 0;
					monsterDrawLimit = 0;
					break;
				case 2:
					floorDrawLimit = 0;//11 floor objects in screen3
					powerupDrawLimit = 0;
					monsterDrawLimit = 0;
					break;
				case 3:
					floorDrawLimit = 0;//4 floor objects in screen 4
					powerupDrawLimit = 0;
					monsterDrawLimit = 0;
					break;
				case 4:
					floorDrawLimit = 0;//8 floor objects in screen 5
					powerupDrawLimit = 0;
					monsterDrawLimit = 0;
					break;
				case 5:
					floorDrawLimit = 0;//7 floor objects in screen 6
					powerupDrawLimit = 0;
					monsterDrawLimit = 0;
					break;
				case 6:
					floorDrawLimit = 0;//4 floor objects in screen 7
					powerupDrawLimit = 0;
					monsterDrawLimit = 0;
					break;
				case 7:
					floorDrawLimit = 0;//7 floor objects in screen 8
					powerupDrawLimit = 0;
					monsterDrawLimit = 0;
					break;
				case 8:
					//checks if all enemies are dead in boss room
					boolean roomClear = true;
					for(int t = 0; t < monsters.size(); t++)
					{
						if(!monsters.get(t).isDead())
						{
							roomClear = false;
						}
					}

					if(roomClear)
					{
						floorDrawLimit = 1;//Boss floor object
					}
					else
					{
						floorDrawLimit = 3;//includes side walls
					}
					powerupDrawLimit = 0;
					monsterDrawLimit = 0;
					break;
				 */
			default:
				floorDrawLimit = 0;
				powerupDrawLimit = 0;
				monsterDrawLimit = 0;
			}

			drawFloors();

			drawPlayer();

			drawHealthLives();

			drawPowerups();

			drawMonsters();

			drawBullets();

			playerMovement();

			bulletMovement();

			monsterMovement();

			playerFloorCollision();

			monsterFloorCollision();

			bulletCollision();

			playerMonsterCollision();

			powerupCollision();

			screenChange();

			incrementFrames();
		}
		else
		{
			canvas.clear();
			pauseMenuSetup();
		}
	}

	public void onKeyPressLevel2()
	{
		keyPressLevels();
	}

	////////////////////
	//Level 3
	///////////////////


	public void level3Setup()
	{
		//change and set the starting point for the player
		player.position(0, 200);

		//screens
		/////////

		Sprite screen1 = makeSprite(getImage("images/level2/screen1/Level2_Screen1.png", 0, 255, 255));
		screen1.position(0, 0);
		/*
			Sprite screen2 = makeSprite(getImage("images/level2/screen2/Level2_Screen2.png", 0, 255, 255));
			screen2.position(0, 0);

			Sprite screen3 = makeSprite(getImage("images/level1/screen3/Level1_Screen3.png", 0, 255, 255));
			screen3.position(0, 0);

			Sprite screen4 = makeSprite(getImage("images/level1/screen4/Level1_Screen4.png", 0, 255, 255));
			screen4.position(0, 0);

			Sprite screen5 = makeSprite(getImage("images/level1/screen5/Level1_Screen5.png", 0, 255, 255));
			screen5.position(0, 0);

			Sprite screen6 = makeSprite(getImage("images/level1/screen6/Level1_Screen6.png", 0, 255, 255));
			screen6.position(0, 0);

			Sprite screen7 = makeSprite(getImage("images/level1/screen7/Level1_Screen7.png", 0, 255, 255));
			screen7.position(0, 0);

			Sprite screen8 = makeSprite(getImage("images/level1/screen8/Level1_Screen8.png", 0, 255, 255));
			screen8.position(0, 0);

			Sprite screen9 = makeSprite(getImage("images/level1/boss/Level1_Boss.png", 0, 255, 255));
			screen9.position(0, 0);
		 */

		screens.add(screen1);
		/*
			screens.add(screen2);
			screens.add(screen3);
			screens.add(screen4);
			screens.add(screen5);
			screens.add(screen6);
			screens.add(screen7);
			screens.add(screen8);
			screens.add(screen9);
		 */

		//floors
		////////

		//Screen 1 Floors
		//Sprite floor1_01 = makeSprite(getImage("images/floor1_01.png", 0, 255, 255));
		//floor1_01.position(0, canvas.height() - floor1_01.height());

		//JD
		int position = 0;
		Sprite floor1_01 =  makeSprite(getImage("images/level2/screen1/floor1_1.png", 0, 255, 255));
		floor1_01.position(position, canvas.height() - floor1_01.height());
		position+=floor1_01.width();

		Sprite floor1_02 = makeSprite(getImage("images/level2/screen1/floor1_2.png", 0, 255, 255));
		floor1_02.position(position, canvas.height() - floor1_02.height());
		position+=floor1_02.width();

		Sprite floor1_03 = makeSprite(getImage("images/level2/screen1/floor1_3.png", 0, 255, 255));
		floor1_03.position(position, canvas.height() - floor1_03.height());
		position+=floor1_03.width();

		Sprite floor1_04 = makeSprite(getImage("images/level2/screen1/floor1_4.png", 0, 255, 255));
		floor1_04.position(position, canvas.height() - floor1_04.height());
		position+=floor1_04.width();

		floors.add(floor1_01);
		floors.add(floor1_02);
		floors.add(floor1_03);
		floors.add(floor1_04);

		/*
			//Screen 2 Floors
			position = 0;
			Sprite floor2_01 = makeSprite(getImage("images/level2/screen2/floor2_1.png", 0, 255, 255));
			floor2_01.position(0, canvas.height() - floor2_01.height() + 10);
			position += floor2_01.width();

			Sprite floor2_02 = makeSprite(getImage("images/level2/screen2/floor2_2.png", 0, 255, 255));
			floor2_02.position(118, canvas.height() - floor2_02.height() + 10);
			position += floor2_02.width();//special case pit in between

			Sprite floor2_03 = makeSprite(getImage("images/level2/screen2/floor2_3.png", 0, 255, 255));
			floor2_03.position(position, canvas.height() - floor2_03.height() + 10);
			position += floor2_03.width();

			Sprite floor2_04 = makeSprite(getImage("images/level2/screen2/floor2_4.png", 0, 255, 255));
			floor2_04.position(position, canvas.height() - floor2_04.height() + 10);
			position += floor2_04.width();

			Sprite floor2_05 = makeSprite(getImage("images/level2/screen2/floor2_5.png", 0, 255, 255));
			floor2_05.position(position, canvas.height() - floor2_05.height() + 10);
			position += floor2_05.width();

			Sprite floor2_06 = makeSprite(getImage("images/level2/screen2/floor2_6.png", 0, 255, 255));
			floor2_06.position(position, canvas.height() - floor2_06.height() + 10);
			position += floor2_06.width();

			Sprite floor2_07 = makeSprite(getImage("images/level2/screen2/floor2_7.png", 0, 255, 255));
			floor2_07.position(position, canvas.height() - floor2_07.height() + 10);
			position += floor2_07.width();

			Sprite floor2_08 = makeSprite(getImage("images/level2/screen2/floor2_8.png", 0, 255, 255));
			floor2_08.position(position, canvas.height() - floor2_08.height() + 10);
			position += floor2_08.width();

			Sprite floor2_09 = makeSprite(getImage("images/level2/screen2/floor2_9.png", 0, 255, 255));
			floor2_09.position(907, canvas.height() - floor2_09.height() + 10);
			position = floor2_09.width();

			Sprite floor2_10 = makeSprite(getImage("images/level2/screen2/floor2_10.png", 0, 255, 255));
			floor2_10.position(position, canvas.height() - floor2_10.height() + 10);
			position += floor2_10.width();

			Sprite floor2_11 = makeSprite(getImage("images/level2/screen2/floor2_11.png", 0, 255, 255));
			floor2_11.position(position, canvas.height() - floor2_11.height() + 10);
			position += floor2_11.width();

			Sprite floor2_12 = makeSprite(getImage("images/level2/screen2/floor2_12.png", 0, 255, 255));
			floor2_12.position(canvas.width() - floor2_12.width(), canvas.height() - floor2_12.height() + 10);
			position += floor2_12.width();

			Sprite floor2_13 = makeSprite(getImage("images/level2/screen2/floor2_13.png", 0, 255, 255));
			floor2_13.position(canvas.width() - floor2_13.width(), canvas.height() - floor2_13.height() + 10);
			position += floor2_13.width();

			Sprite floor2_14 = makeSprite(getImage("images/level2/screen2/floor2_14.png", 0, 255, 255));
			floor2_14.position(canvas.width() - floor2_14.width(), canvas.height() - floor2_14.height() + 10);
			position += floor2_14.width();

			//Sprite platform2_01 = makeSprite(getImage("images/platform1_02.png", 0, 255, 255));
			//platform2_01.position(200, 310);

			floors.add(floor2_01);
			floors.add(floor2_02);
			floors.add(floor2_03);
			floors.add(floor2_04);
			floors.add(floor2_05);
			floors.add(floor2_06);
			floors.add(floor2_07);
			floors.add(floor2_08);
			floors.add(floor2_09);
			floors.add(floor2_10);
			floors.add(floor2_11);
			floors.add(floor2_12);
			floors.add(floor2_13);
			floors.add(floor2_14);


			//floors.add(platform2_01);

			//Screen 3 Floors
			position = 0;
			Sprite floor3_01 = makeSprite(getImage("images/level1/screen3/floor3_1.png", 0, 255, 255));
			floor3_01.position(0, canvas.height() - floor3_01.height() + 10);
			position += floor3_01.width(); 
			System.out.println("position: " + position);


			Sprite floor3_02 = makeSprite(getImage("images/level1/screen3/floor3_2.png", 0, 255, 255));
			floor3_02.position(position, canvas.height() - floor3_02.height());
			position += floor3_02.width();

			System.out.println("position: " + position);
			Sprite floor3_03 = makeSprite(getImage("images/level1/screen3/floor3_3.png", 0, 255, 255));
			floor3_03.position(position, canvas.height() - floor3_03.height());
			position += floor3_03.width();

			System.out.println("position: " + position);
			Sprite floor3_04 = makeSprite(getImage("images/level1/screen3/floor3_4.png", 0, 255, 255));
			floor3_04.position(position, canvas.height() - floor3_04.height());
			position += floor3_04.width();

			System.out.println("position: " + position);
			Sprite floor3_05 = makeSprite(getImage("images/level1/screen3/floor3_5.png", 0, 255, 255));
			floor3_05.position(331, canvas.height() - floor3_05.height());
			position = floor3_05.width()+ 331;

			Sprite floor3_06 = makeSprite(getImage("images/level1/screen3/floor3_6.png", 0, 255, 255));
			floor3_06.position(position, canvas.height() - floor3_06.height());
			position += floor3_06.width();

			Sprite floor3_07 = makeSprite(getImage("images/level1/screen3/floor3_7.png", 0, 255, 255));
			floor3_07.position(position, canvas.height() - floor3_07.height());
			position += floor3_07.width();

			Sprite floor3_08 = makeSprite(getImage("images/level1/screen3/floor3_8.png", 0, 255, 255));
			floor3_08.position(569, canvas.height() - floor3_08.height());
			position = floor3_08.width() + 569;

			Sprite floor3_09 = makeSprite(getImage("images/level1/screen3/floor3_9.png", 0, 255, 255));
			floor3_09.position(position, canvas.height() - floor3_09.height());
			position += floor3_09.width();

			Sprite floor3_10 = makeSprite(getImage("images/level1/screen3/floor3_10.png", 0, 255, 255));
			floor3_10.position(position, canvas.height() - floor3_10.height());
			position += floor3_10.width();

			Sprite floor3_12 = makeSprite(getImage("images/level1/screen3/floor3_12.png", 0, 255, 255));
			floor3_12.position(1142, canvas.height() - floor3_12.height());
			position = floor3_12.width() + 1142;


			Sprite floor3_11 = makeSprite(getImage("images/level1/screen3/floor3_11.png", 0, 255, 255));
			floor3_11.position(position, canvas.height() - floor3_11.height());
			position += floor3_11.width();

			floors.add(floor3_01);
			floors.add(floor3_02);
			floors.add(floor3_03);
			floors.add(floor3_04);
			floors.add(floor3_05);
			floors.add(floor3_06);
			floors.add(floor3_07);
			floors.add(floor3_08);
			floors.add(floor3_09);
			floors.add(floor3_10);
			floors.add(floor3_12);
			floors.add(floor3_11);


			//Screen 4 Floors
			position = 0;
			Sprite floor4_01 = makeSprite(getImage("images/level1/screen4/floor4_1.png", 0, 255, 255));
			floor4_01.position(0, canvas.height() - floor4_01.height() + 10);

			Sprite floor4_02 = makeSprite(getImage("images/level1/screen4/floor4_2.png", 0, 255, 255));
			floor4_02.position(341, canvas.height() - floor4_02.height());
			position += floor4_02.width() + 341;

			Sprite floor4_03 = makeSprite(getImage("images/level1/screen4/floor4_3.png", 0, 255, 255));
			floor4_03.position(position, canvas.height() - floor4_03.height());
			position += floor4_03.width();

			Sprite floor4_04 = makeSprite(getImage("images/level1/screen4/floor4_4.png", 0, 255, 255));
			floor4_04.position(position, canvas.height() - floor4_04.height());
			position += floor4_04.width();

			floors.add(floor4_01);
			floors.add(floor4_02);
			floors.add(floor4_03);
			floors.add(floor4_04);

			//Screen 5 Floors
			position = 0;
			Sprite floor5_01 = makeSprite(getImage("images/level1/screen5/floor5_1.png", 0, 255, 255));
			floor5_01.position(0, canvas.height() - floor5_01.height() + 10);

			Sprite floor5_02 = makeSprite(getImage("images/level1/screen5/floor5_2.png", 0, 255, 255));
			floor5_02.position(328, 167);

			Sprite floor5_03 = makeSprite(getImage("images/level1/screen5/floor5_3.png", 0, 255, 255));
			floor5_03.position(443, canvas.height() - floor5_03.height());

			Sprite floor5_04 = makeSprite(getImage("images/level1/screen5/floor5_4.png", 0, 255, 255));
			floor5_04.position(484, 119);

			Sprite floor5_05 = makeSprite(getImage("images/level1/screen5/floor5_5.png", 0, 255, 255));
			floor5_05.position(515, 66);
			position += floor5_05.width() + 515;

			Sprite floor5_06 = makeSprite(getImage("images/level1/screen5/floor5_6.png", 0, 255, 255));
			floor5_06.position(position, canvas.height() - floor5_06.height());
			position += floor5_06.width();

			Sprite floor5_07 = makeSprite(getImage("images/level1/screen5/floor5_7.png", 0, 255, 255));
			floor5_07.position(position, canvas.height() - floor5_07.height());
			position += floor5_07.width();

			Sprite floor5_08 = makeSprite(getImage("images/level1/screen5/floor5_8.png", 0, 255, 255));
			floor5_08.position(position, canvas.height() - floor5_08.height());

			floors.add(floor5_01);
			floors.add(floor5_02);
			floors.add(floor5_03);
			floors.add(floor5_04);
			floors.add(floor5_05);
			floors.add(floor5_06);
			floors.add(floor5_07);
			floors.add(floor5_08);

			//Screen 6
			position = 0;
			Sprite floor6_01 = makeSprite(getImage("images/level1/screen6/floor6_1.png", 0, 255, 255));
			floor6_01.position(0, canvas.height() - floor6_01.height() + 10);
			position += floor6_01.width();

			Sprite floor6_02 = makeSprite(getImage("images/level1/screen6/floor6_2.png", 0, 255, 255));
			floor6_02.position(position, canvas.height() - floor6_02.height());
			position += floor6_02.width();

			Sprite floor6_03 = makeSprite(getImage("images/level1/screen6/floor6_3.png", 0, 255, 255));
			floor6_03.position(position, canvas.height() - floor6_03.height());
			position += floor6_03.width();

			Sprite floor6_04 = makeSprite(getImage("images/level1/screen6/floor6_4.png", 0, 255, 255));
			floor6_04.position(position, canvas.height() - floor6_04.height());
			position += floor6_04.width();

			Sprite floor6_05 = makeSprite(getImage("images/level1/screen6/floor6_5.png", 0, 255, 255));
			floor6_05.position(position, canvas.height() - floor6_05.height());
			position += floor6_05.width();

			Sprite floor6_06 = makeSprite(getImage("images/level1/screen6/floor6_6.png", 0, 255, 255));
			floor6_06.position(position, canvas.height() - floor6_06.height());
			position += floor6_06.width();

			Sprite floor6_07 = makeSprite(getImage("images/level1/screen6/floor6_7.png", 0, 255, 255));
			floor6_07.position(position, canvas.height() - floor6_07.height());
			position += floor6_07.width();

			floors.add(floor6_01);
			floors.add(floor6_02);
			floors.add(floor6_03);
			floors.add(floor6_04);
			floors.add(floor6_05);
			floors.add(floor6_06);
			floors.add(floor6_07);

			//Screen 7
			position = 0;
			Sprite floor7_01 = makeSprite(getImage("images/level1/screen7/floor7_1.png", 0, 255, 255));
			floor7_01.position(position, canvas.height() - floor7_01.height()+ 5 + 10);
			position += floor7_01.width();

			Sprite floor7_02 = makeSprite(getImage("images/level1/screen7/floor7_2.png", 0, 255, 255));
			floor7_02.position(position, canvas.height() - floor7_02.height());
			position += floor7_02.width();

			Sprite floor7_03 = makeSprite(getImage("images/level1/screen7/floor7_3.png", 0, 255, 255));
			floor7_03.position(position, canvas.height() - floor7_03.height());
			position += floor7_03.width();

			Sprite floor7_04 = makeSprite(getImage("images/level1/screen7/floor7_4.png", 0, 255, 255));
			floor7_04.position(position, canvas.height() - floor7_04.height());
			position += floor7_01.width();

			floors.add(floor7_01);
			floors.add(floor7_02);
			floors.add(floor7_03);
			floors.add(floor7_04);

			//Screen 8
			position = 0;
			Sprite floor8_01 = makeSprite(getImage("images/level1/screen8/floor8_1.png", 0, 255, 255));
			floor8_01.position(position, canvas.height() - floor8_01.height() + 10);
			position += floor8_01.width();

			Sprite floor8_02 = makeSprite(getImage("images/level1/screen8/floor8_2.png", 0, 255, 255));
			floor8_02.position(position, canvas.height() - floor8_02.height());
			position += floor8_02.width();

			floors.add(floor8_01);
			floors.add(floor8_02);

			//Screen 9
			position = 0;
			Sprite floor9_01 = makeSprite(getImage("images/level1/boss/floor9_1.png", 0, 255, 255));
			floor9_01.position(position, canvas.height() - floor9_01.height() + 10);
			position += floor9_01.width();

			floors.add(floor9_01);


			//Boss Walls for boss screen
			bossLeftWall = makeSprite(getImage("images/boss_wall.png", 0, 255, 255));
			bossLeftWall.position(-5, 0);

			bossRightWall  = makeSprite(getImage("images/boss_wall.png", 0, 255, 255));

			bossRightWall.position(canvas.width() - bossRightWall.width(), 0);
			//bossLeftWall.position(0, 0);

			floors.add(bossRightWall);
			floors.add(bossLeftWall);

			//Monsters
			/////////

			//1
			Monster monster1_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
					15, 17);
			monster1_01.position(700, 240);

			monsters.add(monster1_01);

			//2
			Monster monster2_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
					15, 17);
			monster2_01.position(350, 260);

			monsters.add(monster2_01);

			//3
			Monster monster3_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
					15, 17);
			monster3_01.position(900, 220);

			monsters.add(monster3_01);

			//6
			Monster monster6_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
					15, 17);
			monster6_01.position(200, 240);

			Monster monster6_02 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
					15, 17);
			monster6_02.position(670, 200);

			Monster monster6_03 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
					15, 17);
			monster6_03.position(1080, 200);

			monsters.add(monster6_01);
			monsters.add(monster6_02);
			monsters.add(monster6_03);

			//7
			Monster monster7_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
					15, 17);
			monster7_01.position(340, 200);

			Monster monster7_02 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
					15, 17);
			monster7_02.position(816, 190);

			Monster monster7_03 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
					15, 17);
			monster7_03.position(1160, 170);

			monsters.add(monster7_01);
			monsters.add(monster7_02);
			monsters.add(monster7_03);

			//8
			//Monster monster8_01 = new Monster(0, frameCounter, getImage("images/monsters.png", 0, 255, 255),
			//	15, 17);
			//monster8_01.position(1200, 215);

			//monsters.add(monster8_01);

			//Boss Level 2 (Monster Here)
			Monster monster9_01 = new Monster(1000, frameCounter, getImage("images/bosses.png", 0, 255, 255),
					28, 50);
			monster9_01.position(1130, 200);
			monsters.add(monster9_01);

			//powerups
			//////////

			//1
			Powerup power2_01 = new Powerup(1, getImage("images/powerups.png", 0, 255, 255), 20, 20);
			power2_01.position(320, canvas.height() - 35);

			powerups.add(power2_01);
		 */

		startScene("Level3");
	}

	public void drawLevel3()
	{
		if(!paused)
		{
			canvas.clear();

			drawScreens();

			//draw the floors for the specified screen
			switch(index)
			{
			case 0:
				floorDrawLimit = 4;//7 floor objects in screen1
				powerupDrawLimit = 1;
				monsterDrawLimit = 1;
				break;
				/*
			case 1:
				floorDrawLimit = 0;//12 floor objects in screen2
				powerupDrawLimit = 0;
				monsterDrawLimit = 0;
				break;
			case 2:
				floorDrawLimit = 0;//11 floor objects in screen3
				powerupDrawLimit = 0;
				monsterDrawLimit = 0;
				break;
			case 3:
				floorDrawLimit = 0;//4 floor objects in screen 4
				powerupDrawLimit = 0;
				monsterDrawLimit = 0;
				break;
			case 4:
				floorDrawLimit = 0;//8 floor objects in screen 5
				powerupDrawLimit = 0;
				monsterDrawLimit = 0;
				break;
			case 5:
				floorDrawLimit = 0;//7 floor objects in screen 6
				powerupDrawLimit = 0;
				monsterDrawLimit = 0;
				break;
			case 6:
				floorDrawLimit = 0;//4 floor objects in screen 7
				powerupDrawLimit = 0;
				monsterDrawLimit = 0;
				break;
			case 7:
				floorDrawLimit = 0;//7 floor objects in screen 8
				powerupDrawLimit = 0;
				monsterDrawLimit = 0;
				break;
			case 8:
				//checks if all enemies are dead in boss room
				boolean roomClear = true;
				for(int t = 0; t < monsters.size(); t++)
				{
					if(!monsters.get(t).isDead())
					{
						roomClear = false;
					}
				}

				if(roomClear)
				{
					floorDrawLimit = 1;//Boss floor object
				}
				else
				{
					floorDrawLimit = 3;//includes side walls
				}
				powerupDrawLimit = 0;
				monsterDrawLimit = 0;
				break;
				 */
			default:
				floorDrawLimit = 0;
				powerupDrawLimit = 0;
				monsterDrawLimit = 0;
			}

			drawFloors();

			drawPlayer();

			drawHealthLives();

			drawPowerups();

			drawMonsters();

			drawBullets();

			playerMovement();

			bulletMovement();

			monsterMovement();

			playerFloorCollision();

			monsterFloorCollision();

			bulletCollision();

			playerMonsterCollision();

			powerupCollision();

			screenChange();

			incrementFrames();
		}
		else
		{
			canvas.clear();
			pauseMenuSetup();

		}
	}

	public void onKeyPressLevel3()
	{
		keyPressLevels();
	}


	////////////////////
	//Level Functions
	////////////////////

	//Key press in levels handles here
	//////////////////////////////////
	public void keyPressLevels()
	{
		
		//Level Select for for Testing
		if (keyboard.isDown(keyboard.L) && keyboard.ctrl() && keyboard.alt())
		{
			levelSelectSetup();
			
		}
		
		//sound if you push
		//1 to start music(loop)
		//2 to stop music
		if(keyboard.isDown(keyboard.K1))
			level1Music.loop();
		if(keyboard.isDown(keyboard.K2))
			level1Music.stop();

		if(keyboard.isDown(keyboard.P))
		{
			paused = true;
//			println("should pause");

		}
		
		if(keyboard.isDown(keyboard.BACKSPACE)){
			paused = false;
			Robot robot;
			try {
				robot = new Robot();
				robot.keyRelease(KeyEvent.VK_BACK_SPACE);
			} catch (AWTException e) {
				e.printStackTrace();
			}
			
//			println("should unpause");
		}

		if(!paused)
		{
			if(keyboard.isDown(keyboard.SPACE))
			{
				if(airTime < maxAir)
				{
					if(player.y() > 0)
					{
						player.motion(0, -2*speed, ADDONCE);
					}
					else
					{
						player.nextY(0);
					}

					airTime++;
				}
			}
			if(keyboard.isDown(keyboard.RIGHT))
			{
				isFacingLeft = false;
				isFacingRight = true;

				rightPressed = true;

				if(leftPressed)
				{
					isRunning = false;
				}
				else
				{
					isRunning = true;
				}

				player.motion(speed, 0, ADDONCE);
			}
			if(keyboard.isDown(keyboard.LEFT))
			{
				isFacingLeft = true;
				isFacingRight = false;

				leftPressed = true;

				if(rightPressed)
				{
					isRunning = false;
				}
				else
				{
					isRunning = true;
				}

				if(player.x() >= 4)
				{
					player.motion(-speed, 0, ADDONCE);
				}
				else
				{
					player.nextX(0);
				}
			}
			if(keyboard.isDown(keyboard.F))
			{
				isFiring = true;

				int d = 0;

				if(isFacingLeft)
				{
					d = 1;
				}
				else if(isFacingRight)
				{
					d = 0;
				}

				Bullet newBullet =
						new Bullet(currentPowerup, frameCounter, d,
								getImage("images/weapons.png", 0, 255, 255));

				if(isFacingRight)
				{
					newBullet.position(player.x() + player.width()/2,
							player.y() + player.height()/2 - 16);
				}
				else if(isFacingLeft)
				{
					newBullet.position(player.x() - player.width()/2,
							player.y() + player.height()/2 - 16);
				}

				if(bullets.isEmpty())
				{
					bullets.add(newBullet);
				}
				else
				{	
					if(fireOK)
					{
						bullets.add(newBullet);
						fireOK = false;
					}
				}
			}
		}
	}

	//screen drawing
	////////////////
	public void drawScreens()
	{
		if(index < screens.size() && !screens.isEmpty())
		{
			screens.get(index).draw();
		}
	}

	//floor drawing
	///////////////
	public void drawFloors()
	{
		for(int i = 0; !floors.isEmpty() && i < floorDrawLimit; i++)
		{
			floors.get(i).draw();
		}
	}

	//animation check is handled here
	/////////////////////////////////
	public void drawPlayer()
	{
		if(!isRunning)
		{
			if(isFacingLeft)
			{
				player.flipHorizontal();
			}

			if(isFiring)
			{
				player.play("StandFiring");
			}
			else
			{
				player.play("Standing");
			}

			player.draw();
		}
		else
		{
			if(isFacingLeft)
			{
				player.flipHorizontal();
			}

			if(isFiring)
			{
				player.play("RunFiring");
			}
			else
			{
				player.play("Running");
			}

			player.draw();
		}

		isRunning = false;
		isFiring = false;

		leftPressed = false;
		rightPressed = false;
	}

	//health and lives drawing
	//////////////////////////
	public void drawHealthLives()
	{
		for(int lc = 0; lc < currentLives; lc++)
		{
			liveCounter.get(lc).draw();
		}

		for(int h = 0; h < currentHealth; h++)
		{
			healthBar.get(h).draw();
		}
	}

	//bullets drawing
	/////////////////
	public void drawBullets()
	{
		for(int b = 0; b < bullets.size();b++)
		{
			bullets.get(b).draw();
		}
	}

	//monster drawing
	/////////////////
	public void drawMonsters()
	{
		for(int m = 0; !monsters.isEmpty() && m < monsterDrawLimit; m++)
		{
			monsters.get(m).draw();
			//TODO monsters.get(m).drawSpawns();
		}
	}

	//powerup drawing
	/////////////////
	public void drawPowerups()
	{
		for(int p = 0; !powerups.isEmpty() && p < powerupDrawLimit; p++)
		{
			powerups.get(p).draw();
		}
	}

	//player movement and gravity effect
	////////////////////////////////////
	public void playerMovement()
	{
		player.move();

		if(player.y() > canvas.height())
		{
			player.nextY(canvas.height());

			currentHealth = maxHealth;
			currentPowerup = 0;

			currentLives--;
//			if(currentLives <= 0)
//			{
//				startScene("GameOverOverlay");
//			}
			
			setup();
		}
		else
		{
			player.motion(0, gravity, ADDONCE);
		}
	}

	//bullets movement
	//////////////////
	public void bulletMovement()
	{
		for(int b = 0; b < bullets.size(); b++)
		{
			bullets.get(b).move();
		}
	}

	//monster movement
	//////////////////
	public void monsterMovement()
	{
		for(int m = 0; !monsters.isEmpty() && m < monsterDrawLimit; m++)
		{
			if(monsters.get(m).isGravity())
			{
				monsters.get(m).motion(0, gravity, ADDONCE);
			}
			monsters.get(m).move();
			//TODO monsters.get(m).moveSpawns();
		}
	}

	//collisions with floors
	////////////////////////
	public void playerFloorCollision()
	{
		for(int f = 0; !floors.isEmpty() && f < floorDrawLimit; f++)
		{
			player.checkIfCollidesWith(floors.get(f));
			if(player.collided())
			{
				if(player.y() <= (floors.get(f).y() - player.height()))
				{
					player.nextY(floors.get(f).y() - player.height());
					airTime = 0;
				}
				else
				{
					if(player.y() >= (floors.get(f).y() + floors.get(f).height()))
					{
						if(airTime < maxAir)
						{
							player.nextY(floors.get(f).y() + floors.get(f).height());
							airTime = maxAir;
						}
					}
					else
					{
						player.nextX(player.x());
					}
				}
			}
		}
	}

	//monster collisions with floors
	////////////////////////////////
	public void monsterFloorCollision()
	{
		for(int f = 0; !floors.isEmpty() && f < floorDrawLimit; f++)
		{
			for(int m = 0; !monsters.isEmpty() && m < monsterDrawLimit; m++)
			{
				monsters.get(m).checkIfCollidesWith(floors.get(f));
				if(monsters.get(m).collided())
				{
					monsters.get(m).handleFloorCollision(floors.get(f));
				}
			}
		}
	}

	//bullet collisions with monsters
	/////////////////////////////////
	public void bulletCollision()
	{
		for(int b = 0; b < bullets.size(); b++)
		{
			for(int m = 0; !monsters.isEmpty() && m < monsterDrawLimit; m++)
			{
				bullets.get(b).checkIfCollidesWith(monsters.get(m));
				if(bullets.get(b).collided())
				{
					bullets.get(b).position(canvas.width() * 3, canvas.height() * 3);

					//NOTE: all enemies besides first will have 1 less health
					//due to collision detection reasons
					if(monsters.get(m).handleBulletCollision(bullets.get(b)))
					{
						monsters.get(m).position(canvas.width() * 2, canvas.height() * 2);
					}
					else
					{
						monsters.get(m).setFlicker(true);
					}
				}
			}
		}
	}

	//player collisions with monsters
	/////////////////////////////////
	public void playerMonsterCollision()
	{
		for(int m = 0; !monsters.isEmpty() && m < monsterDrawLimit; m++)
		{
			player.checkIfCollidesWith(monsters.get(m));
			if(player.collided())
			{
				int damage = monsters.get(m).handlePlayerCollision(player);
				if(damage > 0 && !invincible)
				{
					invincible = true;
					currentHealth = currentHealth - damage;

					if(currentHealth <= 0)
					{
						currentHealth = maxHealth;
						currentPowerup = 0;

						currentLives--;
//						print(currentLives);
//						if(currentLives <= 0)
//						{
//							
//							print("shouldDie");
//							startScene("GameOverOverlay");
//							
//							
//						}
						
						setup();
					}
				}
				else if(damage < 0)
				{
					monsters.get(m).position(canvas.width() * 2, canvas.height() * 2);
				}
			}
		}
	}

	//collision with powerups
	/////////////////////////
	public void powerupCollision()
	{
		for(int p = 0; !powerups.isEmpty() && p < powerupDrawLimit; p++)
		{
			player.checkIfCollidesWith(powerups.get(p));
			if(player.collided())
			{
				currentPowerup = powerups.get(p).getType();
				powerups.get(p).position(canvas.width() * 2, canvas.height() * 2);
			}
		}
	}

	//screen change is handled here
	///////////////////////////////
	public void screenChange()
	{
		if(player.x() >= canvas.width())
		{
			if(index < screens.size())
			{
				index++;
			}

			player.position(0, player.y());

			bullets.clear();

			//remove previous floors
			for(int a = 0; !floors.isEmpty() && a < floorDrawLimit; a++)
			{
				floors.remove(0);
			}

			//remove previous monsters
			for(int m = 0; !monsters.isEmpty() && m < monsterDrawLimit; m++)
			{
				monsters.remove(0);
			}

			//remove previous powerups
			for(int p = 0; !powerups.isEmpty() && p < powerupDrawLimit; p++)
			{
				powerups.remove(0);
			}

			//changes to score menu at level's end
			if(index >= screens.size())
			{
				startScene("ScoreMenu");
			}
		}
	}

	//frame counter increment
	/////////////////////////
	public void incrementFrames()
	{
		frameCounter++;

		//handles fire rate of bullets
		if(!bullets.isEmpty())
		{
			int frame = bullets.get(bullets.size() - 1).getStartFrame();
			int rate = bullets.get(bullets.size() - 1).getFireRate();

			if(rate <= 0 || ((frameCounter - frame) % frameMod) % rate == 0)
			{
				fireOK = true;
			}
		}

		//player invincibility
		if(invincible)
		{
			currentInvincibleFrame++;

			if(currentInvincibleFrame % 4 == 0)
			{
				player.hide();
			}
			else
			{
				player.show();
			}

			if(currentInvincibleFrame % maxInvincibleFrames == 0)
			{
				invincible = false;
				currentInvincibleFrame = 0;
				player.show();
			}
		}

		//monster flicker
		for(int m = 0; !monsters.isEmpty() && m < monsterDrawLimit; m++)
		{
			//the monster.size() check is due to ordering of
			//incrementFrames() and screenCheck()
			if(m < monsters.size() && monsters.get(m).isFlicker())
			{
				currentMonsterFlicker++;

				if(currentMonsterFlicker % 4 == 0)
				{
					monsters.get(m).hide();
				}
				else
				{
					monsters.get(m).show();
				}

				if(currentMonsterFlicker % maxMonsterFlicker == 0)
				{
					monsters.get(m).setFlicker(false);
					currentMonsterFlicker = 0;
					monsters.get(m).show();
				}
			}
		}

		if(frameCounter % frameMod == 0)
		{
			frameCounter = 0;
		}

		//give all monsters the current frame and player position
		for(int f = 0; f < monsters.size(); f++)
		{
			monsters.get(f).setCurrentFrame(frameCounter);
			monsters.get(f).givePlayer(player);
		}
	}

	///////////////
	//Menus
	//////////////
	
	public void mainMenuSetup(){
		//MainMenuButtons		
		startbtn = makeButton("StartBtn", getImage("images/menus/StartButton.png", 0, 0, 0),325, 40);
		//		leaderbtn = makeButton("LeaderboardBtn",getImage("images/menus/LeaderBoardBtn.png", 0, 0, 0), 325, 40);
		levelbtn = makeButton("LevelSelectBtn",getImage("images/menus/levelSelectBtn.png", 0, 0, 0), 325, 40);
		quitbtn = makeButton("QuitBtn",getImage("images/menus/quitBtn.png", 0, 0, 0),325, 40);
		mainMenu = makeSprite(getImage("images/menus/MainMenuBackDrop.png"));
		tutorialBtn = makeButton("TutorialBtn",getImage("images/menus/Tutorialbtn.png",0,0,0),325,40);
		showMainMenu();
		startScene("MainMenu");
	}	

		
	public void gameOverSetup(){
		//Game over buttons
		gameOverQuit = makeButton("GameOverQuit",smallQuit,200,30);
		gameOver = makeSprite(getImage("images/menus/GameOver.png"));
		showGameOverOverlay();
		startScene("GameOverOverlay");
	}
	
	public void pauseMenuSetup(){

		//Pause Menu buttons
		pausedScreen = makeSprite(getImage("images/menus/Paused.png"));
		pauseQuit = makeButton("PauseQuit",smallQuit,200,30);
		pauseResume = makeButton("PauseResume",getImage("images/menus/PauseResumeBtn.png",0,0,0),200,30);
		restartBtn = makeButton("Restart", restartImg,200,30 );
		showPauseOverlay();
		startScene("PauseOverlay");
	}
	
	public void  levelSelectSetup(){
		//Level Select Buttons
		levelSelectBG = makeSprite(getImage("images/menus/LevelSelect.png"),533,400);
		lvl1 = makeButton("Lvl1",getImage("images/menus/1.png"),200,40);
		lvl2 = makeButton("Lvl2",getImage("images/menus/2.png"),200,40);
		lvl3 = makeButton("Lvl3",getImage("images/menus/3.png"),200,40);
		lvlback = makeButton("LvlBack" , getImage("images/menus/lvlslctback.png"),200,40);
		showLevelSelect();
		startScene("LevelSelect");
	}
	
	
	public void tutorialSetup(){
		
		//Tutorial
		tutorialScreen = makeSprite(getImage("images/menus/tutorialScreen.jpg"));
		tutorialBack = makeButton("TutorialBack" , getImage("images/menus/lvlslctback.png"),200,40);
		showTutorialScreen();
		startScene("Tutorial");
	}

	//	A few helper methods to center sprites

	private double centerSpriteHorizontal(Sprite toCenter){
		return canvas.width()/2 - toCenter.width()/2;
	}

	private double centerSpriteVertical(Sprite toCenter){
		return canvas.height()/2 - toCenter.height()/2;
	}

	private double setSpriteVerticalPosition(Sprite toCenter, double position, int num_buttons){
		return canvas.height()/2 - ((toCenter.height()*num_buttons)/2) + toCenter.height()*position;
	}
	
	private double setSpriteHorizontalPosition(Sprite toCenter, double position, int num_buttons){
		return canvas.width()/2 - ((toCenter.width()*num_buttons)/2) + toCenter.width()*position;
	}
	/////////////////////
	//Game Over Overlay//
	/////////////////////

	public void drawGameOverOverlay(){
	
		canvas.clear();
		canvas.background(0, 0, 0);
		gameOver.position(centerSpriteHorizontal(gameOver), setSpriteVerticalPosition(gameOver,0,NUM_GAME_OVER_BUTTONS));
		gameOver.draw();
		gameOverQuit.position(centerSpriteHorizontal(gameOverQuit), setSpriteVerticalPosition(gameOverQuit,1,NUM_GAME_OVER_BUTTONS));
		gameOverQuit.draw();


	}
	
	public void hideGameOverOverlay(){
		gameOver.hide();
		gameOverQuit.hide();
	}
	
	public void showGameOverOverlay(){
		gameOver.show();
		gameOverQuit.show();
	}
	
	public void onClickGameOverQuit(){	
		isGameplay = false;
		currentLives = maxLives;
		hideGameOverOverlay();
		setup();	
	}
	
	public void showRestartBtn(int pos, int buttons){
    	restartBtn.position(centerSpriteHorizontal(restartBtn), setSpriteVerticalPosition(restartBtn,pos,buttons));
    	restartBtn.show();
//    	println("showRestartBtn end");
	}

	////////////////
	//Title Screen//
	////////////////

	public void drawTitleScreen(){
		//		window.size(MAIN_MENU_WIDTH, MAIN_MENU_HEIGHT);
		canvas.clear();
		canvas.background(0,0,0);
		titleScreen.position(centerSpriteHorizontal(titleScreen), centerSpriteVertical(titleScreen));
		titleScreen.draw();
	}

	public void onKeyPressTitleScreen(){
		if(keyboard.isDown(keyboard.ENTER)){
			mainMenuSetup();
			
		}
	}


	/////////////
	//Main Menu//
	/////////////	
	

	public void drawMainMenu(){
		canvas.clear();
		canvas.background(0,0,0);


		mainMenu.position(centerSpriteHorizontal(mainMenu), centerSpriteVertical(mainMenu));
		mainMenu.draw();
		startbtn.position(centerSpriteHorizontal(startbtn), setSpriteVerticalPosition(startbtn,0,NUM_MAIN_MENU_BUTTONS));
		startbtn.draw();
//		leaderbtn.position(centerSpriteHorizontal(leaderbtn), setSpriteVerticalPosition(leaderbtn,1));
//		leaderbtn.draw();
		levelbtn.position(centerSpriteHorizontal(levelbtn), setSpriteVerticalPosition(levelbtn,1,NUM_MAIN_MENU_BUTTONS));
		levelbtn.draw();
		tutorialBtn.position(centerSpriteHorizontal(tutorialBtn), setSpriteVerticalPosition(tutorialBtn,2,NUM_MAIN_MENU_BUTTONS));
		tutorialBtn.draw();
		
		quitbtn.position(centerSpriteHorizontal(quitbtn), setSpriteVerticalPosition(quitbtn,3,NUM_MAIN_MENU_BUTTONS));
		quitbtn.draw();

	}
	
	public void hideMainMenu(){

		mainMenu.hide();
		startbtn.hide();
//		leaderbtn.hide();
		tutorialBtn.hide();
		levelbtn.hide();
		quitbtn.hide();
//		print("hiding menus\n");

		startScene("CanvasClear");
	}

	public void showMainMenu(){
		mainMenu.show();
		startbtn.show();
		levelbtn.show();
		tutorialBtn.show();
		quitbtn.show();
	}
	
    public void onClickStartBtn()
    {
 
        isGameplay = true;
        currentLevel = 0;
        hideMainMenu();
		setup();

    }
    
    public void onClickLeaderboardBtn()
    {
        print("LeaderBoard functionality\n");
    }
    
    public void onClickLevelSelectBtn()
    {
    	hideMainMenu();
    	levelSelectSetup();
    }
    
    public void onClickTutorialBtn()
    {
    	hideMainMenu();
    	tutorialSetup();
    }
    
    public void onClickQuitBtn()
    {
//    	print("quit game functionality \n");
        try {
			Robot robot = new Robot();
			robot.keyPress(KeyEvent.VK_ESCAPE);
		} catch (AWTException e) {
			e.printStackTrace();
		}     
    }
    
    /////////////////////
    //Level Select Menu//
    /////////////////////
    
    public void drawLevelSelect(){
    	canvas.clear();
    	canvas.background(0,0,0);
    	
    	levelSelectBG.position(centerSpriteHorizontal(levelSelectBG), centerSpriteVertical(levelSelectBG));
    	levelSelectBG.draw();
    	lvl1.position(centerSpriteHorizontal(lvl1), setSpriteVerticalPosition(lvl1,0,4));
    	lvl1.draw();
    	lvl2.position(centerSpriteHorizontal(lvl2), setSpriteVerticalPosition(lvl2,1,4));
    	lvl2.draw();
    	lvl3.position(centerSpriteHorizontal(lvl3), setSpriteVerticalPosition(lvl3,2,4));
    	lvl3.draw();
    	lvlback.position(centerSpriteHorizontal(lvlback), setSpriteVerticalPosition(lvlback,3,4));
    	lvlback.draw();
    }
    
    public void showLevelSelect(){
    	levelSelectBG.show();
    	lvl1.show();
    	lvl2.show();
    	lvl3.show();
    	lvlback.show();
    }
    
    public void hideLevelSelect(){
    	lvlback.hide();
    	levelSelectBG.hide();
    	lvl1.hide();
    	lvl2.hide();
    	lvl3.hide();
    	startScene("CanvasClear");
    }
    
    public void drawCanvasClear(){
    	canvas.clear();
    }
    
    public void onClickLvl1(){
    	println("onClicklvl1");
    	currentLevel =0;
    	isMarathon = false;
    	isGameplay = true;
    	hideLevelSelect();
    	setup();

    }
    
    public void onClickLvl2(){
    	println("onClicklvl2");
    	currentLevel =1;
    	isMarathon = false;
    	isGameplay = true;
    	hideLevelSelect();
    	setup();
    }
    
    public void onClickLvl3(){
    	println("onClicklvl3");
    	currentLevel =2;
    	isMarathon = false;
    	isGameplay = true;
    	hideLevelSelect();
    	setup();
    }
    
    public void onClickLvlBack(){
    	hideLevelSelect();
    	mainMenuSetup();
    }
    
    
    
    //Tutorial
    
    public void drawTutorial(){
    	
    	canvas.clear();
    	tutorialScreen.position(0,0);
    	tutorialScreen.draw();
    	tutorialBack.position(1050, 256);
    	tutorialBack.draw();
    	
    }
    
    public void showTutorialScreen(){
    	tutorialScreen.show();
    	tutorialBack.show();
    }
    
    public void hideTutorialScreen(){
    	tutorialScreen.hide();
    	tutorialBack.hide();
    	startScene("CanvasClear");
    }
    
    public void onClickTutorialBack(){
    	hideTutorialScreen();
    	mainMenuSetup();
    }
    
    
    
    
	/////////////////
    //Pause Overlay//
    /////////////////
    
    public void drawPauseOverlay(){

	
			canvas.clear();
			pausedScreen.position(centerSpriteHorizontal(pausedScreen), setSpriteVerticalPosition(pausedScreen,0,4));
	    	pausedScreen.draw();
			pauseResume.position(centerSpriteHorizontal(pauseResume), setSpriteVerticalPosition(pauseResume,1,4));
			pauseQuit.position(centerSpriteHorizontal(pauseQuit), setSpriteVerticalPosition(pauseQuit,3,4));
			pauseQuit.draw();
			pauseResume.draw();	
	    	restartBtn.position(centerSpriteHorizontal(restartBtn), setSpriteVerticalPosition(restartBtn,2,4));
	    	restartBtn.draw();		
		
    }
    
    public void showPauseOverlay(){
    	restartBtn.show();
    	pausedScreen.show();
    	pauseQuit.show();
    	pauseResume.show();
//    	print("showPauseOverlay\n");
    }
    
    public void hidePauseOverlay(){
    	pausedScreen.hide();
    	pauseQuit.hide();
    	pauseResume.hide();
    	restartBtn.hide();
//    	print("hidePauseOverlay\n");
    	startScene("CanvasClear");
    }
    
    public void onClickPauseQuit(){
    	isGameplay = false;	
    	hidePauseOverlay();
    	paused = false;
		startScene("TitleScreen");	
    }
    
    public void onClickPauseResume(){
    	hidePauseOverlay();
        try {
			Robot robot = new Robot();
			robot.keyPress(KeyEvent.VK_BACK_SPACE);
			
		} catch (AWTException e) {
			e.printStackTrace();
		}   
        startScene("Level"+(currentLevel+1));
    }
    
    public void onClickRestart(){   	
//    	print("onclickRestart\n");
    	hidePauseOverlay();
    	setup();

    }
    
    
    
	
	//Score Menu
	////////////
	public void drawScoreMenu()
	{
		canvas.clear();		
		

		if (isMarathon){
			if (currentLevel == 0){
			//Level 1 Complete
				canvas.background(getImage("images/menus/lvl1tolvl2.png"));
				level1Complete = makeSprite(getImage("images/menus/Level1Complete.png"));
				level1Complete.position(centerSpriteHorizontal(level1Complete), centerSpriteVertical(level1Complete));
				level1Complete.draw();
				
			}else if (currentLevel == 1){
				canvas.background(getImage("images/menus/lvl2tolvl3.png"));
				level2Complete = makeSprite(getImage("images/menus/Level2Complete.png"));
				level2Complete.position(centerSpriteHorizontal(level2Complete), centerSpriteVertical(level2Complete));
				level2Complete.draw();
			}else if (currentLevel >= MAX_LEVELS){
				canvas.background(256,256,256);
				levelComplete = makeSprite(getImage("images/menus/GameComplete.png"));
				levelComplete.position(centerSpriteHorizontal(levelComplete), centerSpriteVertical(levelComplete));
				levelComplete.draw();
			}
			
		}else{
			canvas.background(0, 0, 0);
			levelComplete= makeSprite(getImage("images/menus/LevelComplete.png"));
			levelComplete.position(centerSpriteHorizontal(levelComplete), centerSpriteVertical(levelComplete));
			levelComplete.draw();
		}
			
		


	}

	public void onKeyPressScoreMenu()
	{
		if(keyboard.isDown(keyboard.ENTER))
		{
			if(isMarathon && currentLevel <= MAX_LEVELS)
			{
				currentLevel++;
				isGameplay = true;
				setup();
			}
			else
			{
				currentLevel = 0;
				isGameplay = false;
				isMarathon = true;
				mainMenuSetup();
			}
		}
	}
}